package com.smartrodin.springbootrabbitmq.controller;

import com.smartrodin.springbootrabbitmq.service.IMqSendFileLogService;
import com.smartrodin.springbootrabbitmq.service.TestService;
import com.smartrodin.springbootrabbitmq.util.Constant;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: arnold_nie
 * @date: 2020/7/25 10:45
 * FileName: DirectController
 * Description: 路由模式测试 controller
 */
@RestController
@RequestMapping("/mq")
public class DirectController {

    @Autowired
    private IMqSendFileLogService sendFileLogService;

    @Autowired
    private TestService testService;

    @ApiOperation(value = "发送路由模式消息")
    @RequestMapping(value = "/directTest", method = RequestMethod.GET)
    public String directTest() {
        sendFileLogService.sendMsgAndRecord( "direct 用户注册发送消息。。。。。。", "routingKey.userRegister", Constant.PUSH_DATA_DIRECT_EXCHANGE, 1 );
        sendFileLogService.sendMsgAndRecord( "direct 订单支付成功消息。。。。。。", "routingKey.orderPaySuccess", Constant.PUSH_DATA_DIRECT_EXCHANGE, 1 );
        return "direct 模式消息成功";
    }

    @ApiOperation(value = "发布/订阅(类似广播)模式消息")
    @RequestMapping(value = "/fanoutTest", method = RequestMethod.GET)
    public String fanoutTest() {
        sendFileLogService.sendMsgAndRecord( "fanout 类型发送消息。。。。。。", null, Constant.PUSH_DATA_FANOUT_EXCHANGE, 1 );
        return "fanout 模式消息成功";
    }

    @ApiOperation(value = "topic 通配符模式消息")
    @RequestMapping(value = "/topicTest", method = RequestMethod.GET)
    public String topicTest() {
        sendFileLogService.sendMsgAndRecord( "topic 类型发送消息。。。。。。orderPayStatus", "test.orderPayStatus", Constant.PUSH_DATA_TOPIC_EXCHANGE, 1 );
        sendFileLogService.sendMsgAndRecord( "topic 类型发送消息。。。。。。orderSingleDiscount", "test.orderSingleDiscount", Constant.PUSH_DATA_TOPIC_EXCHANGE, 1 );
        return "topic 模式消息成功";
    }

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String test() {
        testService.test();
        return  "OK";

    }
}
